﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DTO;

namespace nhakhoachauau
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["del"] != null)
            {
                if(Request.QueryString["del"].Equals("on"))
                {
                    if (Request.QueryString["id"] != null)
                    {
                        int id;
                        if (int.TryParse(Request.QueryString["id"], out id))
                        {
                            Q_BUSChi BUSchi = new Q_BUSChi();
                            BUSchi.XoaPhieuChi(id);
                        }
                    }
                }
            }
        }

        protected void btnLuuVaXuatPhieuChi_Click(object sender, EventArgs e)
        {
            Q_BUSChi BUSChi = new Q_BUSChi();
            Chi chi = new Chi();
            chi.id_nhanvien = int.Parse(ddlNhanVienLap.SelectedValue);
            chi.ngay_chi_tien = DateTime.Now.Date;
            chi.so_tien_chi = decimal.Parse(txtSoTienChi.Value.Split(' ')[0]);
            chi.ly_do_chi = txtLyDoChi.Value;
            try
            {
                BUSChi.ThemPhieuChi(chi);
                Response.Redirect("~/lap-phieu-chi.aspx");
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
        }

        protected void ddlNhanVienLap_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                Q_BUSNhanVien BUSnv = new Q_BUSNhanVien();
                List<NhanVien> dsNhanVien = BUSnv.DanhSachNhanVienLamViec();
                ddlNhanVienLap.DataSource = dsNhanVien;
                ddlNhanVienLap.DataTextField = "ho_ten";
                ddlNhanVienLap.DataValueField = "id";
                ddlNhanVienLap.DataBind();
            }
        }

        //protected void lbtnXoa_Click(object sender, EventArgs e)
        //{
        //    Q_BUSChi BUSchi = new Q_BUSChi();
        //    int id = int.Parse(Request["idchi"]);
        //    BUSchi.XoaPhieuChi(id);
        //}
    }
}